package zhieasy.cn.common.utils;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * 数学工具类
 * @author zouchanglin
 */
public class MathUtil {
    private static final double THRESHOLD_VALUE = 0.01F;

    /**
     * 比较小数是否相等，阈值视情况而定
     */
    public boolean compareDecimal (float num, float num2){
        return Math.abs(num - num2) < THRESHOLD_VALUE;
    }

    /**
     * 比较小数是否相等，阈值视情况而定
     */
    public boolean compareDecimal (double num, double num2){
        return Math.abs(num - num2) < THRESHOLD_VALUE;
    }

    /**
     * 计算经纬度之间的距离
     * @param gpsFrom
     * @param gpsTo
     * @return
     */
    public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo) {
        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.WGS84, gpsFrom, gpsTo);
        return geoCurve.getEllipsoidalDistance();
    }
}
